﻿<%@ Control Language="C#" Inherits="Yuanlin.Business.UserListControl, Yuanlin.Business" AutoEventWireup="true" %>
<%@ Import Namespace="System.Web.Core" %>
<%@ Import Namespace="Yuanlin.Business" %>

<script language="javascript" type="text/javascript">

function resetUserPassword(userId){
    var bool = confirm("确认重置该用户密码吗？");
    if(bool == false){
        return;
    }
    AjaxMethod.ResetUserPassword('<%= ClientID %>', userId, refreshPage4);
}
function lockUser(userId){
    var bool = confirm("确认冻结该用户吗？");
    if(bool == false){
        return;
    }
    AjaxMethod.LockUser('<%= ClientID %>', userId, refreshPage2);
}
function unLockUser(userId){
    var bool = confirm("确认解冻该用户吗？");
    if(bool == false){
        return;
    }
    AjaxMethod.UnLockUser('<%= ClientID %>', userId, refreshPage3);
}

function deleteUser(userId){
    var bool = confirm("确认删除该用户吗？");
    if(bool == false){
        return;
    }
    AjaxMethod.DeleteUser('<%= ClientID %>', userId, refreshPage);
}

function deleteUsers(){

    var check = document.getElementsByName("userId");
    var ifSelect;
    var userIds = '';
    for(var i=0;i<check.length;i++){
        if(check[i].checked==true){
            if(userIds == '')
                userIds = check[i].value;
            else
                userIds = userIds + ":" + check[i].value;
            ifSelect = true;
        }
    }
    if(ifSelect == true){
        var delSelect = confirm("确认删除这些用户吗？");
        if(delSelect == false){
            return;
        }
        AjaxMethod.DeleteUsers('<%= ClientID %>', userIds, refreshPage);
    }
    else{
        alert("请选择要删除的记录！");
    }

}

function updateCheckAllChecked(check){
    var checkAll = document.getElementById("CheckAll");
    if(!check.checked){
        checkAll.checked = false;
    }
    else
    {
        var ifAllSelect = true;
        var check = document.getElementsByName("userId");
        for(var i=0;i<check.length;i++){
            if(check[i].checked==false){
                ifAllSelect = false;
            }
        }
        if(ifAllSelect == true){
            checkAll.checked = true;
        }
    }
}

function toggleAllCheck(checkAll){
    var check = document.getElementsByName("userId");
    for(var i=0;i<check.length;i++){
        check[i].checked=checkAll.checked;
    }
}

function refreshPage(res)
{
    if (res.value == 0)
    {
        alert('您当前要删除的用户不存在！');
        return;
    }
    else if (res.value == -1)
    {
        alert('系统管理员帐号不能被删除！');
        return;
    }
    window.location.reload();
    var checkAll = document.getElementById("CheckAll");
    checkAll.checked = false;
    toggleAllCheck(checkAll);
}

function refreshPage2(res)
{
    if (res.value == 0)
    {
        alert('您当前要冻结的用户不存在！');
        return;
    }
    else if (res.value == -1)
    {
        alert('系统管理员帐号不能被冻结！');
        return;
    }
    window.location.reload();
    var checkAll = document.getElementById("CheckAll");
    checkAll.checked = false;
    toggleAllCheck(checkAll);
}

function refreshPage3(res)
{
    if (res.value == 0)
    {
        alert('您当前要解冻的用户不存在！');
        return;
    }
    window.location.reload();
    var checkAll = document.getElementById("CheckAll");
    checkAll.checked = false;
    toggleAllCheck(checkAll);
}

function refreshPage4(res)
{
    alert(res.value);
    return;
}

</script>

<fieldset>
    <legend>用户管理</legend>

    <asp:Repeater id="list" runat="server">
        <HeaderTemplate>
            <table border="0" cellpadding="0" cellspacing="0" class="AdminTable">
                <thead>
                    <tr>
                        <th class="NumCol"><input type="checkbox" onclick="toggleAllCheck(this)" id="CheckAll" title="全选/取消全选" /></th>
                        <th class="TitleCol">用户昵称</th>
                        <th class="BigActionCol">操作</th>
                    </tr>
                </thead>
                <tbody>
        </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td class="NumCol">
                    <input type="checkbox" onclick="updateCheckAllChecked(this)" name="userId" id="userId" value="<%# ((System.Web.Core.User)Container.DataItem).EntityId.Value %>" />
                </td>
                <td class="TitleCol">
                    <%# ((YuanlinUser)Container.DataItem).CompanyName.Value%>
                </td>
                <td class="BigActionCol">
                    <a href="javascript:void(0);" style="display:<%# ((YuanlinUser)Container.DataItem).UserStatus.Value == 1 ? "none" : "" %>;" onclick="lockUser(<%# ((YuanlinUser)Container.DataItem).EntityId.Value %>)" alt="冻结帐号" title="冻结当前用户的帐号"><span>冻结</span></a><a href="javascript:void(0);" style="display:<%# ((YuanlinUser)Container.DataItem).UserStatus.Value == 0 ? "none" : "" %>;color:<%# ((YuanlinUser)Container.DataItem).UserStatus.Value == 0 ? "#000000" : "#FF0000" %>" onclick="unLockUser(<%# ((YuanlinUser)Container.DataItem).EntityId.Value %>)" alt="解冻帐号" title="解冻当前用户的帐号"><span>解冻</span></a>
                    <a href="javascript:void(0);" onclick="resetUserPassword(<%# ((YuanlinUser)Container.DataItem).EntityId.Value %>)" title="重置当前用户的密码"><span>重置密码</span></a>
                    <a href="javascript:void(0);" onclick="deleteUser(<%# ((YuanlinUser)Container.DataItem).EntityId.Value %>)" title="删除"><span>删除</span></a>
                </td>
            </tr>
        </ItemTemplate>
        <FooterTemplate>
                </tbody>
            </table>
            <div class="FormRow ButtonRow">
                <input type="button" class="Button" onclick="deleteUsers()" value="删除选择"/>&nbsp;&nbsp;&nbsp;&nbsp;
            </div>
        </FooterTemplate>
    </asp:Repeater>
    <div class="PagingWrapper">
        <asp:Panel ID="Panel1" Runat="server" align="right" CssClass="CommonPagingArea">
            <nwap:CurrentPage Cssclass="columnText" id="currentPage" runat="server" />
            <nwap:Pager id="pager" runat="server" PageSize="20" />
        </asp:Panel>
    </div>
</fieldset>